﻿namespace IBTrader.Indicator.CandleStick
{
    using IBTrader.Indicator.Average;
    using IBTrader.Charts;

    /// <summary>
    /// The Force Index is an indicator that uses price and volume to assess the power behind a move or identify possible turning points. 
    /// Developed by Alexander Elder, the Force Index was introduced in his classic book, Trading for a Living. 
    /// According to Elder, there are three essential elements to a stock's price movement: direction, extent and volume. 
    /// The Force Index combines all three as an oscillator that fluctuates in positive and negative territory as the balance of power shifts. 
    /// The Force Index can be used to reinforce the overall trend, identify playable corrections or foreshadow reversals with divergences.
    /// </summary>
    class ForceIndex : BaseVolume
    {
        private readonly EMA ema;
        public ForceIndex(Worker worker, int interval = 60, int pinterval = 13)
            : base(worker, 1, interval, pinterval)
        {
            ema = new EMA(worker, pinterval);
            ema.Hit += (_, line) => OnHit(line, line.Price);
        }
        protected override void Add(object sender, Item item)
        {
            ema.Add(sender, NewLine(item, (item.Close - (this as ILast).Last.Close) * item.Volume));
        }
    }
}